package resources;

import com.faithlibraryplus.Codecs;

/**
 *
 * @author jiaf
 */
public class Query{
    public static String insert(String record, String table){
        return String.format("INSERT INTO %s VALUES (%s)", table, record);
    }
    
    public static String delete(String table, String condition){
        return String.format("DELETE FROM %s WHERE %s", table, condition);
    }
    
    public static String update(String table, String set, String condition){
        return String.format("UPDATE %s SET %s WHERE %s", table, set, condition);
    }
    
    public static String[] parse(String table, String q){
    	String [] result = {"", "", "", ""};
    	q = q.replace(String.format("UPDATE %s SET ", table), "");
    	q = q.replace(" WHERE ", ",").replace("Status=", "").
    			replace("Owner=", "").replace("Return_Date=", "").
    			replace("id=", "").replace("'", "");
    	result[0] = Codecs.decode(q.split(",")[0]);
    	result[1] = Codecs.decode(q.split(",")[1]);
    	result[2] = Codecs.decode(q.split(",")[2]);
    	result[3] = Codecs.decode(q.split(",")[3]);
    	return result;
    }
}
